package yun1.shuxue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 非十进制 转 十进制：按权展开 
 *    123D = 1*10^2 + 2* 10^1 + 3*10^0
 *    111011B = 11D
 *    8421 
 */

public class ToTen {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		
		String[] arr = line.split(" ");
		
		for(int i=0;i<arr.length;i++) {
			String front = arr[i].substring(0, arr[i].length()-1);//取前n-1个字符，1001B,子串的区间[ ),前闭后开
			char last = arr[i].charAt(arr[i].length()-1);//取每个字符串最后一位字符
			if(last == 'B') {
				System.out.print(Integer.parseInt(front, 2));
			}
			if(last == 'O') {
				System.out.print(Integer.parseInt(front, 8));
			}
			if(last == 'H') {
				System.out.print(Integer.parseInt(front, 16));
			}
			if(i<arr.length-1) {
				System.out.print(" ");
			}
		}	
		System.out.println();		
		System.out.println(Integer.toString(2992, 12));
	}
}
